<template>
  <div>
    <table>
      <tr>
        <th>编号</th>
        <th>品牌名称</th>
        <th>创立时间</th>
        <th>操作</th>
      </tr>

      <tr v-for="(item, index) in arr" :key="item.id">
        <td>{{ item.id }}</td>
        <td>{{ item.name }}</td>
        <td>{{ item.year }}</td>
        <td><button @click="del(index)">删除</button></td>
      </tr>

      <tr v-if="arr.length === 0">
        <td colspan="4">没有数据</td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: [
        { id: 1, name: "奔驰", year: "2020 - 08 - 01" },
        { id: 2, name: "宝马", year: "2020 - 08 - 02" },
        { id: 3, name: "奥迪", year: "2020 - 08 - 03" },
      ],
    };
  },
  methods: {
    del(index) {
      this.arr.splice(index, 1);
    },
  },
};
</script>

<style>
table {
  width: 600px;
  height: 200px;
  border: 1px solid #ddd;
  border-collapse: collapse;
  text-align: center;
}
th,
td {
  border: 1px solid #ddd;
}
th {
  background-color: skyblue;
}
</style>
